import { defineStore } from "pinia";
import { toMaskData, toTradingViewData } from "@/comm/format";

interface IState {
    subscriberList: {
        callback: Function;
    };
    maskList: {
        callback: Function;
    };
    tradingViewData: [];
    chartsType: String;
    description: String;
}

export const useTradingView = defineStore("TradingView", {
    state: (): IState => ({
        subscriberList: {
            callback: () => {}
        },
        maskList: {
            callback: Function
        },
        tradingViewData: [],
        chartsType: "TradingView",
        description: ""
    }),
    actions: {
        // 改变tradingView周期
        setInterval() {
            let cycle: any = {
                MN1: "1m",
                MN5: "5m",
                MN15: "15m",
                MN30: "30m",
                H1: "1h",
                H4: "4h",
                D1: "1d",
                W1: "1w"
            };
            let k_type = localStorage.getItem("K_TIME") || "D1";
            this.description = cycle[k_type];
        },
        upData(data: any) {
            let temp = toTradingViewData(data.data);
            this.subscriberList.callback(temp);
        },
        upMaskData(data: any) {
            //     let temp =[ ]
            //    temp.push(toMaskData(data))
            // this.maskList.callback(data)
        },
        changeType(type: String) {
            this.chartsType = type;
        }
    }
});
